﻿package com.google.ads.studio.creative.swipe {
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.display.Loader;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.utils.getQualifiedSuperclassName;
	
	import com.greensock.TweenLite;
		
	/**
	* SwipeThumbnail Class
	* Thumbnail for the SwipeBar Class.
	* 
	* @autor: Emilio Mora (emiliom@google.com)
	* @version: 0.2
	* @langversion AS3
	*
	*/	
	public class SwipeThumbnail extends MovieClip {
		
		private var _id:int;

		/**
		* Constructor.
		*
		* @param id Id of the panel to open.
		* @param image Image for the thumbnail, can be a MovieClip, BitmapData or a URL to an image.
		*/
		public function SwipeThumbnail(id:int, image:Object) {			
			
			if (getQualifiedSuperclassName(image) == "flash.display::MovieClip") {
				var imageMovie:MovieClip = new image();
				this.addChild(imageMovie);
			} else if (getQualifiedSuperclassName(image) == "flash.display::BitmapData") {
				var bitmapData:BitmapData = new image(0,0);
				var bitmap:Bitmap = new Bitmap(bitmapData);
				this.addChild(bitmap);
			} else if (image is String) {
				var imageLoader:Loader = new Loader();
				imageLoader.load( new URLRequest (image as String) );
				this.addChild(imageLoader);
			} else {
				throw new Error('Invalid thumbnail image, the image need to be a MovieClip, BitmapData or file path');
			}
			
			_id = id;
			
			this.buttonMode = true;
			this.mouseChildren = false;
			
			this.addEventListener(MouseEvent.MOUSE_OVER, mouseOverEffect);
			this.addEventListener(MouseEvent.MOUSE_OUT, mouseOutEffect);
			
		}
		
		private function mouseOverEffect(event:MouseEvent) {
			TweenLite.to(event.currentTarget, 0.5, {alpha:0.6});
		}
		
		private function mouseOutEffect(event:MouseEvent) {
			TweenLite.to(event.currentTarget, 0.5, {alpha:1});
		}
		
		/**
		* Get the id of the panel.
		* 
		* @return the value of the id.
		*/
		public function get id():int {
			return _id;
		}


	}
	
}
